home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / audioio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  4.8 KB  |  146 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef ARTS_AUDIOIO_H
  24. #define ARTS_AUDIOIO_H
  25.  
  26. #include <startupmanager.h>
  27. #include <string>
  28. #include "arts_export.h"
  29. /*
  30.  * BC - Status (2002-03-08): AudioIO, AudioIOFactory
  31.  *
  32.  * Right now, these classes are considered an implementation detail. No binary
  33.  * compatibility guaranteed, its safe to add virtual methods when required.
  34.  */
  35.  
  36. /*
  37.  * The AudioIO class - it is used as follows:
  38.  *
  39.  *   1. check the settings with getParam, modify what you don't like
  40.  *   2. call open -> print getInfo(lastError) if it failed (returned false)
  41.  *   3. check whether the settings are still what you expected them to
  42.  *      be (as the AudioIO class will maybe only know after open if the
  43.  *      requested parameters can be achieved)
  44.  */
  45.  
  46. namespace Arts {
  47.  
  48. class AudioIOPrivate;
  49. class AudioIOFactory;
  50.  
  51. class ARTS_EXPORT AudioIO {
  52. private:
  53.     class AudioIOPrivate *d;
  54.  
  55. public:
  56.     enum AudioParam {
  57. /* the following has to be supported */
  58.         samplingRate = 1,    /* usually 4000..48000 (Hz) */
  59.         channels = 2,        /* usually 1 (mono) or 2 (stereo) */
  60.         format = 3,            /*    8  = 8bit unsigned
  61.                              *  16 = 16bit signed little endian
  62.                              *    17 = 16bit signed big endian
  63.                              *  32 = 32bit float */
  64.  
  65. /* the following -can- be supported (value=-1 if they are not) */
  66.         direction = 101,    /* 1 = read, 2 = write, 3 = read|write */
  67.         fragmentCount = 102,/* usually 3..16 (to control latency) */
  68.         fragmentSize = 103,    /* usually 256,512,...8192 (a 2^N value) */
  69.         canRead = 104,        /* the amount of bytes that can be read */
  70.         canWrite = 105,        /* the amount of bytes that can be written */
  71.         selectReadFD = 106,    /* filedescriptor to be select()ed on for reading */
  72.         selectWriteFD = 107,/* filedescriptor to be select()ed on for writing */
  73.         autoDetect = 108,    /* 0 = don't use this as default 
  74.                              * 1 or higher = preference of using this as default
  75.                              *
  76.                              * if nothing else is specified, aRts asks all
  77.                              * available AudioIO classes for the autoDetect
  78.                              * value and chooses the one which returned the
  79.                              * highest number */
  80.  
  81. /* string parameters that have to be supported */
  82.         lastError = 201,    /* the last error message as human readable text */
  83.  
  84. /* string parameters that -can- be supported */
  85.         deviceName = 301,    /* name of the device to open */
  86.  
  87. /* class parameters: same semantics as above */
  88.         name = 1201,        /* name of the driver (i.e. oss) */
  89.         fullName = 1202        /* full name (i.e. Open Sound System) */
  90.     };
  91.  
  92.     enum {
  93.         directionRead = 1,
  94.         directionWrite = 2,
  95.         directionReadWrite = 3
  96.     };
  97.  
  98.     AudioIO();
  99.     virtual ~AudioIO();
  100.  
  101.     virtual void setParamStr(AudioParam param, const char *value);
  102.     virtual void setParam(AudioParam param, int& value);
  103.     virtual int getParam(AudioParam param);
  104.     virtual const char *getParamStr(AudioParam param);
  105.  
  106.     virtual bool open() = 0;
  107.     virtual void close() = 0;
  108.     virtual int read(void *buffer, int size) = 0;
  109.     virtual int write(void *buffer, int size) = 0;
  110.  
  111. /* ---- factory querying stuff ---- */
  112.     static int queryAudioIOCount();
  113.     static int queryAudioIOParam(int audioIO, AudioParam param);
  114.     static const char *queryAudioIOParamStr(int audioIO, AudioParam param);
  115.  
  116. /* ---- factory stuff ---- */
  117.     static AudioIO *createAudioIO(const char *name);
  118.     static void addFactory(AudioIOFactory *factory);
  119.     static void removeFactory(AudioIOFactory *factory);
  120.  
  121. protected:
  122.     int& param(AudioParam param);
  123.     std::string& paramStr(AudioParam param);
  124. };
  125.  
  126. class ARTS_EXPORT AudioIOFactory : public StartupClass {
  127. public:
  128.     void startup();
  129.     void shutdown();
  130.     virtual AudioIO *createAudioIO() = 0;
  131.     virtual const char *name() = 0;
  132.     virtual const char *fullName() = 0;
  133. };
  134.  
  135. }
  136.  
  137. #define REGISTER_AUDIO_IO(impl,implName,implFullName)                \
  138.     static class AudioIOFactory ## impl : public AudioIOFactory {    \
  139.     public:                                                            \
  140.         AudioIO *createAudioIO() { return new impl(); }                \
  141.         virtual const char *name() { return implName; }                \
  142.         virtual const char *fullName() { return implFullName; }        \
  143.     } The_ ## impl ## _Factory /* <- add semicolon when calling this macro */
  144.  
  145. #endif /* ARTS_AUDIOIO_H */
  146.